package com.gragra.nounIdentification.tests;

import static org.junit.Assert.*;
import java.io.BufferedReader;
import java.io.StringReader;
import org.junit.Before;
import org.junit.Test;
import com.gragra.data.Corpus;
import com.gragra.nounIdentification.ConvergenceByTypeCoverage;
import com.gragra.nounIdentification.IncreasingMaxWithMin;
import com.gragra.nounIdentification.LinearIncreasingMax;
import com.gragra.nounIdentification.NounIdentifier;
import com.gragra.nounIdentification.TypesPerTokenScorer;
import com.gragra.sampling.sequentialStructure.WordAndTagHolder;
import com.gragra.sequentiaDataGenerator.BaseGenerator;
import com.gragra.sequentiaDataGenerator.CaseLevelAssigningSegmenter;
import com.gragra.sequentiaDataGenerator.PunctuationSplitOffSegmenter;

public class TestConvergenceByTypeCoverage
{
	/**
	 * 
	 */
	private NounIdentifier ni;
	/**
	 * 
	 */
	private ConvergenceByTypeCoverage cbt;
	@Before
	public void setUp() throws Exception
	{
		this.cbt = new ConvergenceByTypeCoverage(0.5);
		StringReader sr = new StringReader("A|NONE Cat|1 is|0 on|NONE the|0 mat.|NONE\nA|g horse|NONE is|0 on|NONE the|0 grass.|NONE\nA|j mouse|NONE is|0 in|NONE the|0 trap.|NONE");
		BufferedReader br = new BufferedReader(sr);
		BaseGenerator bg = new BaseGenerator(new CaseLevelAssigningSegmenter(new PunctuationSplitOffSegmenter("NONE")));
		Corpus<WordAndTagHolder>  corp = bg.createCorpus(br);
		ni = new NounIdentifier(corp, 3, 0, 0, new TypesPerTokenScorer(),this.cbt, new IncreasingMaxWithMin(new LinearIncreasingMax(1, 1), 2, 5));
		ni.identify();
	}
	@Test
	public void testHasConverged()
	{assertTrue(ni.calculateWordTypeCoverage()>=0.5);}
}